package org.example.everyday;

import java.util.Map;

/**
 * <p>
 * Description:TODO 详细描述
 * <p>
 * <p>
 *
 * @author anlu
 * @date 2022/7/2 0002 21:46
 */
public class Lc871 {
    public static void main(String[] args) {
        Lc871 lc871 = new Lc871();
        int target = 100, startFuel = 10;
        int[][] stations = {{10,60},{20,30},{30,30},{60,40}};
        int res = lc871.minRefuelStops(target,startFuel,stations);
        System.out.println(res);
    }

    /**
     * 方法描述: [10, 70, 110, 140, 170]
     *
     * @param target .
     * @param startFuel .
     * @param stations .
     * @return int
     * @author 安路路
     * @date 2022/7/2 0002  22:22
     */
    public int minRefuelStops(int target, int startFuel, int[][] stations) {
        int n = stations.length;
        long[] dp = new long[n + 1];
        dp[0] = startFuel;

        for (int i = 0; i < n; i++) {
            for (int j = i; j >=0 ; j--) {
                if(dp[j] >= stations[i][0]){
                    dp[j + 1] = Math.max(dp[j+1], dp[j] + stations[i][1]);
                }
            }
        }
        for (int i = 0; i <= n; i++){
            if(dp[i] >= target){
                return i;
            }
        }
        return -1;
    }
}
